package com.share.design.interpreter;

import lombok.AllArgsConstructor;

/**
 * author:caifan
 * date:2020/2/6
 */
@AllArgsConstructor
public class Variable implements Expression {

    private String name;

    @Override
    public boolean interprete(Context context) {
        return context.lookup(this);
    }

    @Override
    public boolean equals(Object obj) {
        if(obj != null && obj instanceof Variable) {
            return this.name.equals(
                    ((Variable)obj).name);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.toString().hashCode();
    }

    @Override
    public String toString() {
        return name;
    }
}
